﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;

namespace _2014112107
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {

            string strCn = "server=pc.hstc.cn;database=dhd2014112107;uid=2014112107;password=19951106";
            SqlConnection cn = new SqlConnection(strCn);

            try
            {
                if (this.rdoManager.Checked)
                {
                    cn.Open();
                    string strSql = "SELECT * FROM ManageInfo where UserName =N'" + this.txtUserName.Text + "'";
                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    SqlDataReader c = cmd.ExecuteReader();
                    string password = "";
                    //string Sname = ""; 
                    if (c.Read())
                    {
                        password = (string)c.GetValue(1);
                        if (password == txtPwd.Text)
                        {




                            Response.Write("<script>alert('欢迎您进入财务管理系统!');window.location.href ='ManagerMain.aspx'</script>");
                        }
                        else
                        {

                            Response.Write("<script>alert('密码错误，请重新输入！');</script>");
                        }

                    }
                    else
                    {
                        Response.Write("<script>alert('连接失败！');</script>");
                    }
                    c.Close();

                }
                else
                {
                    if (this.rdoUser.Checked)
                    {
                        cn.Open();
                        string strSql = "SELECT * FROM UserInfo where UserName =N'" + this.txtUserName.Text + "'";
                        SqlCommand cmd = new SqlCommand(strSql, cn);
                        SqlDataReader c = cmd.ExecuteReader();
                        string password = "";

                        if (c.Read())
                        {
                            password = (string)c.GetValue(1);
                            if (password == txtPwd.Text)
                            {

                                Response.Write("<script>alert('欢迎您进入财务管理系统!');window.location.href ='UserMain.aspx'</script>");
                            }
                            else
                            {
                                Response.Write("<script>alert('密码错误，请重新输入！');</script>");
                            }

                        }
                        else
                        {

                            Response.Write("<script>alert('不好意思,此用户不存在！');</script>");
                        }
                        c.Close();
                    }

                }
            }
            catch
            {
                Response.Write("<script>alert('连接失败！');</script>");
            }
            finally
            {
                cn.Close();
            }
        }


          

       


        protected void btnRegister_Click(object sender, EventArgs e)
        {
            Response.Redirect("Register.aspx");
        }
    }
}